//Pad签署使用的js
//pad地址端口
var port;
/**
 * 提交签署
 */
var first_getImgInterval;
var second_getImgInterval;
var loading;
function submitInfo (){
    $.ajax({
        type: "POST",
        data:$('#createContract').serialize(),
        url: port,
        dataType:"json",
        timeout: 60000,
        async:false,
        success:function(msg){
            if(null != msg ) {
                if(msg.result == 'OK'){
                    loading = layer.load(3, {content:'请在PAD上进行签署！',time:150000,
                            success: function(layero){
                            layero.find('.layui-layer-content').css({"padding-top":"40px","background-position":"center center","padding-left":"0"});
                        }})
                    first_getImgInterval = setInterval(getSignImg,2000);
                    return;
                }else{
                    layer.alert("PAD响应指令失败!");
                    return;
                }
            } else {
                layer.alert("指令发送失败!");
                return;
            }
        }
    });
}

//获取签名图片
var getSignImg = function (){
    $.ajax({
        type: "POST",
        url: port,
        data:$("#getForm").serialize(),
        dataType:"json",
        async:false,
        success:function(msg){
            if(null != msg){
                if(msg.result=="OK"){
                    if (null != msg.sign_pic) {
                        $("#qianming").attr("src", "data:image/png;base64,"+msg.sign_pic);
                        $("#signName").val("data:image/png;base64,"+msg.sign_pic);
                        $(".btn").removeAttr("disabled");
                        $("#comint").attr("disabled","disabled");
                        layer.close(loading);
                        clearInterval(first_getImgInterval);
                        clearInterval(second_getImgInterval);
                    }
                }
            }else{
                layer.alert("指令发送失败!");
                return;
            }
        }
    });
}


function sub(flag) {
    if(flag=='1'){
        $(".btn").attr("disabled","disabled");
        $.ajax({
            type: "POST",
            data:$('#homeForm').serialize(),
            url: port,
            timeout: 60000,
            dataType:"json",
            success:function(msg){
                if(null != msg) {
                    if(msg.result=='OK') {
                        notice();
                        $(".btn").removeAttr("disabled");
                        return;
                    } else {
                        layer.alert("PAD响应指令失败!");
                        $(".btn").removeAttr("disabled");
                        return;
                    }
                } else {
                    layer.alert("指令发送失败!");
                    return;
                }
                
            }
        });
        return;
    }
    if(flag=='2'){
        $("#qianming").attr("src","");
        $.ajax({
            type: "POST",
            data:$('#redoForm').serialize(),
            url: port,
            dataType:"json",
            async:false,
            success:function(msg){
                if(null != msg){
                    if(msg.result == 'OK'){
                        second_getImgInterval = setInterval(getSignImg,2000);
                        return;
                    }else{
                        layer.alert("PAD响应指令失败!");
                        return;
                    }
                }else{
                    layer.alert("指令发送失败!");
                    return;
                }
            }
        });
    }
    if(flag=='3'){
        $.ajax({
            type: "POST",
            data:$('#cancelForm').serialize(),
            url: port,
            timeout: 60000,
            dataType:"json",
            success:function(msg){
                if(null != msg){
                    if(msg.result=='OK'){
                    	closeParentIframe();
                        return;
                    } else {
                        layer.alert("PAD响应指令失败!");
                        return;
                    }
                }else{
                    layer.alert("指令发送失败!");
                    return;
                }
            }
        });
        return;
    }
}
function notice(){
    var signbase64=$("#qianming").attr("src");
    $("#signbase64").attr("value",signbase64);
    layer.alert("传送数据成功!");
}
